package priority;

class MyThread extends Thread{
    private String name;
    public MyThread(String name){
        this.name=name;
    }

    @Override
    public void run() {
        for (int i=1;i<=10;i++){
            System.out.println("线程"+name+"正在运行"+i+"次!");
        }
    }
}
public class PriorityDemo {
    public static void main(String[] args) {
        //获取主线程的优先级  currentThread():获取当前线程
        int mainPriority=Thread.currentThread().getPriority();
        System.out.println("主线程的优先级为:"+mainPriority);

        MyThread mt1=new MyThread("线程1");
        MyThread mt2=new MyThread("线程2");
        //设置线程优先级
        mt1.setPriority(8);
        //设置mt2的线程优先级为最小
        mt2.setPriority(Thread.MIN_PRIORITY);
        mt1.start();
        mt2.start();
        System.out.println("线程1的优先级为:"+mt1.getPriority());
        System.out.println("线程2的优先级为:"+mt2.getPriority());
    }
}
